package com.wx.registerclient.heartbeat;


import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
import org.springframework.stereotype.Component;


import java.io.IOException;



/**
 * 心跳包
 */
@Component
public class HeartBeat {

    /*private static  CloseableHttpClient build;
    static {
        // 初始化客服端
       build = HttpClientBuilder.create().build();
    }
*/
    public  boolean getServerStatus(String url){

        CloseableHttpClient  build = HttpClientBuilder.create().build();
        //发送get请求确定状态
        HttpGet get = new HttpGet(url);
        try {
            CloseableHttpResponse execute = build.execute(get);
            int statusCode = execute.getStatusLine().getStatusCode();
            if(statusCode==200){
                return true;
            }else {
                return false;
            }
        } catch (IOException e) {
          // 发送请求异常
            return false;
        }

    }



}
